import { loadEnv, ConfigEnv, UserConfigExport } from 'vite'
import vue from '@vitejs/plugin-vue'
import path from 'path'
import process from 'process'


export default ({ command, mode }: ConfigEnv): UserConfigExport => {

  const { VITE_BASE_URL, VITE_PROXY_URL } = loadEnv(mode, process.cwd())


  return {
    plugins: [vue()],
    base: VITE_BASE_URL,
    resolve: {
      alias: {
        '@': path.resolve(__dirname, 'src')
      }
    },
    server: {
      proxy: {
        '/api': {
          target: VITE_PROXY_URL,
          changeOrigin: true,
          rewrite: (path) => path.replace(/^\/api/, '')
        }
      }
    }
  }

}


